﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BFlatCompile.Serializer
{
	internal static class Phase24GatherRawSource
	{
		public static string Do(Compiler compiler, List<string[]> sourceCode)
		{
			if (compiler.IsReadable)
			{
				return "N/A";
			}

			StringBuilder b = new StringBuilder();

			foreach (string[] file in sourceCode)
			{
				string filename = file[0];
				string code = file[1];
				string toSerialize = filename + '|' + code;
				string value = Util.ConvertStringToHex(compiler, toSerialize);
				string length = Util.ToHex(compiler, value.Length, 8);

				b.Append(length);
				b.Append(value);
			}

			return b.ToString();
		}
	}
}
